/*
 * Copyright IBM Japan, AMS Services 2003 ALL Rights Reserved <br /> <br />.
 *
 * This product includes software developed by
 * the Apache Software Foundation (http://www.apache.org/).
 */
package com.tianqu.tms.core.taglib;

import java.text.DecimalFormat;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;

import org.apache.struts.taglib.TagUtils;

/**
 * 
 * IRIS�V�X�e�� <br />
 * ������Format�̏���
 * 
 * <br />
 * <br />
 *
 * <b>ChangeLog </b> <br />
 * 1.0 2009/11/06 <br />
 * <br />
 *
 */
public class NumFormatTag extends BodyTagSupport {
    
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/**
     * The body content of this tag (if any).
     */
    protected String text = null;
	
	/**
     * Save the associated label from the body content.
     *
     * @exception JspException if a JSP exception has occurred
     */
    public int doAfterBody() throws JspException {

        if (bodyContent != null) {
            String value = bodyContent.getString().trim();
            if (value.length() > 0) {
            	DecimalFormat format = new DecimalFormat("###,###,###");
                text = format.format(Long.valueOf(value).longValue());
            } else {
            	text = "0";
            }
        } else {
        	text = "0";
        }
        return (SKIP_BODY);
        

    }
    
    /**
     * Process the end of this tag.
     * 
     * Support for Indexed property since Struts 1.1
     *
     * @exception JspException if a JSP exception has occurred
     */
    public int doEndTag() throws JspException {
        TagUtils.getInstance().write(pageContext, text);
        return (EVAL_PAGE);
    }
}
